package tree

// preTreeRecursive 前序
func preTreeRecursive(root *TreeNode) []int {
	result := make([]int, 0)
	if root == nil {
		return result
	}
	result = append(result, root.Val)
	result = append(result, preTreeRecursive(root.Left)...)
	result = append(result, preTreeRecursive(root.Right)...)
	return result
}

// inTreeRecursive 中序
func inTreeRecursive(root *TreeNode) []int {
	result := make([]int, 0)
	if root == nil {
		return result
	}
	result = inTreeRecursive(root.Left)
	result = append(result, root.Val)
	result = append(result, inTreeRecursive(root.Right)...)
	return result
}

// postTreeRecursive 后序
func postTreeRecursive(root *TreeNode) []int {
	result := make([]int, 0)
	if root == nil {
		return result
	}
	result = postTreeRecursive(root.Left)
	result = append(result, postOrderTraversal(root.Right)...)
	result = append(result, root.Val)
	return result
}

func getHeightOfTree(root *TreeNode) int {
	if root == nil {
		return 0
	}
	leftHeight := getHeightOfTree(root.Left)
	rightHeight := getHeightOfTree(root.Right)
	if leftHeight > rightHeight {
		return leftHeight + 1
	} else {
		return rightHeight + 1
	}
}
